<template>
  <view>
    <view class="patient-base">
      <view class="genetic-height">
        遗传身高<view class="height">{{ props.geneticHeightData?.[0]?.value }}</view>cm
        <image src="@/static/icon/question.svg" class="question-icon" @tap="showTips" />
      </view>
      <view class="height-data">
        <view class="data-item">
          <text>年龄</text>
          <view class="data-value-line">
            <text v-if="props.topData?.ageYear > 0">
              <text class="data-value">{{ props.topData.ageYear }}</text>岁
            </text>
            <view class="data-value" v-if="props.topData?.ageYear == 0 && props.topData?.ageMonth == 0">
              未满月
            </view>
            <text v-if="props.topData?.ageYear < 18 && props.topData?.ageMonth > 0">
              <text class="data-value">{{ props.topData.ageMonth }}</text>月
            </text>
          </view>
        </view>
        <view class="data-item" v-for="item in props.topData.list" :key="item.code">
          <text>{{ item.name }}</text>
          <view class="data-value-line"><text class="data-value">{{ item.value }}</text>{{ item.unit }}</view>
        </view>
      </view>
    </view>
    <view class="charts-wrap">
      <view class="charts-title">
        <text>身高发育曲线</text>
        <view>
          <RadioGroup 
            :options="options" 
            v-model="chartType" 
          />
        </view>
      </view>
      <!-- <view class="unit">单位：cm</view> -->
      <view class="charts-box">
        <height-echarts
          :patientId="props.patientInfo.id"
          :userSex="props.patientInfo.gender"
          :type="chartType"
          ref="heightEchartsRef"
          style="width: 100%; height: 100%"
        />
      </view>
    </view>
    <view class="height-list">
      <view class="list-title">明细记录</view>
      <view v-for="item in props.heightDetailList" :key="item.id" class="list-item">
        <view class="title">
          {{ proxy.utils.date.format(item.recordDate, 'yyyy-MM-dd') }}
          <text>{{ item.ageYear > 0 ? item.ageYear + '岁' : '' }}{{ item.ageMonth == 0 && item.ageYear == 0 ? '未满月' : item.ageYear < 18 && item.ageMonth != 0 ? item.ageMonth + '月' : '' }}</text>
        </view>
        <view class="height-wrap">
          <view v-for="(item_in, index) in item.items" :key="index" class="height-item">
            <view class="item">{{ item_in.name }}<text class="status" :style="{ background: colorsMap[item_in.status]?.bg, color: colorsMap[item_in.status]?.color }">{{ colorsMap[item_in.status]?.label }}</text></view>
            <view class="item"><text class="value">{{ item_in.value }}</text>{{ item_in.unit }}</view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref, getCurrentInstance, watch } from 'vue';
import HeightEcharts from '@/pages/height-echarts/index.vue'
import RadioGroup from './radio-group.vue';

const { proxy } : any = getCurrentInstance();
const props = defineProps({
  patientInfo: {
    type: Object,
    default: () => {}
  },
  heightDetailList: {
    type: Array,
    default: () => []
  },
  topData: {
    type: Object,
    default: () => {}
  },
  geneticHeightData: {
    type: Array,
    default: () => []
  }
});

const colorsMap = {
  low_height: {
    bg: 'rgba(255, 129, 60, 0.10)',
    color: 'rgba(255, 129, 60, 1)',
    label: '偏矮'
  },
  high_height: {
    bg: 'rgba(92, 142, 255, 0.10)',
    color: 'rgba(92, 142, 255, 1)',
    label: '偏高'
  },
  normal: {
    bg: 'rgba(12, 182, 124, 0.10)',
    color: 'rgba(12, 182, 124, 1)',
    label: '正常'
  },
  slightly_high_height: {
    bg: 'rgba(2, 188, 195, 0.10)',
    color: 'rgba(2, 188, 195, 1)',
    label: '稍高'
  },
  slightly_low_height: {
    bg: 'rgba(255, 129, 60, 0.10)',
    color: 'rgba(255, 129, 60, 1)',
    label: '稍矮'
  },
  high_weight: {
    bg: 'rgba(92, 142, 255, 0.10)',
    color: 'rgba(92, 142, 255, 1)',
    label: '偏胖'
  },
  low_weight: {
    bg: 'rgba(255, 129, 60, 0.10)',
    color: 'rgba(255, 129, 60, 1)',
    label: '偏瘦'
  },
}

const heightEchartsRef = ref<any>()
const chartType = ref<string>('PValue') //  PValue | SDValue
const options = ref([
  { value: 'PValue', label: 'P值' },
  { value: 'SDValue', label: 'SD值' }
]);
watch(() => [chartType.value, props.heightDetailList], () => {
  heightEchartsRef.value?.setData(props.patientInfo.id, props.patientInfo.gender, chartType.value)
})

const showTips = () => {
  uni.showModal({
    content: "遗传身高是根据父母身高计算的统计学数据，非小朋友真实情况，且有上下5cm浮动范围",
    showCancel: false,
    confirmText: "知道了",
    confirmColor: "#00D1B6"
  });
}
</script>

<style scoped lang="scss">
.patient-base {
  margin: 22rpx 32rpx 0;
  border-radius: 24rpx;
  border-top: 2rpx solid #FFFFFF;
  background: linear-gradient(to bottom, #F4FEFC 0%,  #FFFFFF 90rpx, #FFFFFF 100%);
  padding: 24rpx 32rpx 40rpx;
  font-size: 28rpx;
  color: #666666;
  .genetic-height {
    display: flex;
    align-items: center;
    padding-bottom: 24rpx;
    border-bottom: 1rpx solid #E5E6EB;
    .height {
      font-size: 40rpx;
      font-weight: bold;
      color: #222222;
      margin-left: 16rpx;
      margin-right: 8rpx;
    }
    .question-icon {
      width: 30rpx;
      height: 28rpx;
      // @include flex-center-center;
      margin-left: 14rpx;
    }
  }
  .height-data {
    display: flex;
    justify-content: space-between;
    padding-top: 40rpx;
    .data-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 20rpx;
      .data-value-line {
        display: flex;
        align-items: center;
        .data-value {
          font-size: 40rpx;
          color: #222222;
          font-weight: 600;
        }
      }
    }
  }
}
.charts-wrap {
  margin: 32rpx 32rpx 0;
  border-radius: 24rpx;
  border-top: 2rpx solid #FFFFFF;
  background: linear-gradient(to bottom, #F4FEFC 0%, #FFFFFF 90rpx, #FFFFFF 100%);
  padding: 32rpx;
  .charts-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 32rpx;
    color: #222222;
    font-weight: bold;
    border-bottom: 1rpx solid #E5E6EB;
    padding-bottom: 32rpx;
  }
  .unit {
    font-size: 24rpx;
    color: #666666;
    padding: 20rpx 0;
  }
  .charts-box {
    width: 100%;
    height: 600rpx;
    padding-top: 16rpx;
  }
}
.height-list {
  margin: 32rpx 32rpx 0;
  border-radius: 24rpx;
  border-top: 2rpx solid #FFFFFF;
  background: linear-gradient(to bottom, #F4FEFC 0%, #FFFFFF 90rpx, #FFFFFF 100%);
  padding: 32rpx;
  .list-title {
    font-size: 32rpx;
    color: #222222;
    font-weight: bold;
    border-bottom: 1rpx solid #E5E6EB;
    padding-bottom: 32rpx;
  }
  .list-item {
    margin-top: 24rpx;
    color: #222222;
    .title {
      font-size: 30rpx;
      display: flex;
      gap: 20rpx;
      // justify-content: space-between;
      align-items: center;
    }
    .height-wrap {
      margin-top: 18rpx;
      border-radius: 16rpx;
      padding: 32rpx;
      background: #FAFAFA;
      display: flex;
      flex-direction: column;
      gap: 16rpx;
      font-size: 28rpx;
      .height-item {
        display: flex;
        justify-content: space-between;
        .item {
          display: flex;
          align-items: center;
          .status {
            border-radius: 4rpx;
            padding: 2rpx 20rpx;
            font-size: 24rpx;
            margin-left: 16rpx;
          }
          .value {
            font-size: 40rpx;
            font-weight: bold;
            margin-right: 24rpx;
          }
        }
      }
    }
  }
}
</style>
